package logic

import (
	"context"
	"hem/hemrpc/hemrpcclient"

	"hem/api/internal/svc"
	"hem/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HemAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHemAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HemAddLogic {
	return &HemAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HemAddLogic) HemAdd(req *types.HemAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.HemAdd(l.ctx, &hemrpcclient.HemAddRequest{
		Title: req.Title,
		Image: req.Image,
		Price: float32(req.Price),
		Num:   int64(req.Num),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    500,
			Code:    nil,
		}, nil
	}

	return &types.Response{
		Message: "商品添加成功",
		Data:    200,
		Code:    add,
	}, nil

}
